本文整理汇总了C#中System.CodeDom.CodeTypeReference类的典型用法代码示例。如果您正苦于以下问题:C# CodeTypeReference类的具体用法?C# CodeTypeReference怎么用?C# CodeTypeReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeTypeReference类属于System.CodeDom命名空间,在下文中一共展示了CodeTypeReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeTypeReference type = new CodeTypeReference ("System.Int32");
CodeTypeReferenceExpression ctre = new CodeTypeReferenceExpression (type);
Assert.AreSame (type, ctre.Type, "Type");
ctre.Type = new CodeTypeReference ("System.Void");
}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeTypeReferenceExpressionCas.cs
示例2: ProcessProperty
protected override void ProcessProperty(CodeTypeDeclaration type, CodeMemberField field, CodeMemberProperty property)
{
if (property.Type.ArrayElementType == null) return; // Is array?
if (property.Name == "Items" || property.Name == "ItemsElementName") return;
CodeTypeReference genericType = new CodeTypeReference("System.Collections.Generic.List", new CodeTypeReference(property.Type.BaseType));
property.Type = genericType;
if (field != null) {
field.Type = genericType;
property.GetStatements.Insert(0,
// if
new CodeConditionStatement(
// field == null
new CodeBinaryOperatorExpression(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name),
CodeBinaryOperatorType.IdentityEquality,
new CodePrimitiveExpression(null)),
// field = new List<T>();
new CodeAssignStatement(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name),
new CodeObjectCreateExpression(genericType))));
}
}
开发者ID:dsrbecky,项目名称:ColladaDOM,代码行数:26,代码来源:ArraysToGenericExtension.cs
示例3: GetParameterTypeReference
internal static CodeTypeReference GetParameterTypeReference(CodeTypeDeclaration classDeclaration,
IParameter param)
{
Type underlyingType = GetParameterType(param);
CodeTypeReference paramTypeRef = new CodeTypeReference(underlyingType);
bool isValueType = underlyingType.IsValueType;
// Check if we need to declare a custom type for this parameter.
// If the parameter is an enum, try finding the matching enumeration in the current class
if (!param.EnumValues.IsNullOrEmpty())
{
// Naming scheme: MethodnameParametername
CodeTypeReference enumReference = DecoratorUtil.FindFittingEnumeration(
classDeclaration, param.EnumValues, param.EnumValueDescriptions);
if (enumReference != null)
{
paramTypeRef = enumReference;
isValueType = true;
}
}
// Check if this is an optional value parameter.
if (isValueType && !param.IsRequired)
{
paramTypeRef = new CodeTypeReference(typeof(Nullable<>))
{
TypeArguments = { paramTypeRef.BaseType }
};
// An optional value parameter has to be nullable.
}
return paramTypeRef;
}
开发者ID:artzub,项目名称:LoggenCSG,代码行数:34,代码来源:ResourceBaseGenerator.cs
示例4: ComputeForType
private CodeTypeReference ComputeForType(Type type)
{
// we know that we can safely global:: qualify this because it was already
// compiled before we are emitting or else we wouldn't have a Type object
CodeTypeReference value = new CodeTypeReference(type, CodeTypeReferenceOptions.GlobalReference);
return value;
}
开发者ID:uQr,项目名称:referencesource,代码行数:7,代码来源:TypeReference.cs
示例5: EmitField
private void EmitField(CodeTypeDeclaration typeDecl, CodeTypeReference fieldType, bool hasDefault)
{
CodeMemberField memberField = new CodeMemberField(fieldType, Utils.FieldNameFromPropName(Item.Name));
memberField.Attributes = MemberAttributes.Private;
AttributeEmitter.AddGeneratedCodeAttribute(memberField);
if (hasDefault)
{
if (this.Generator.UseDataServiceCollection)
{
// new DataServiceCollection<T>(null, System.Data.Services.Client.TrackingMode.None, null, null, null);
// declare type is DataServiceCollection<T>
Debug.Assert(fieldType.TypeArguments.Count == 1, "Declare type is non generic.");
// new DataServiceCollection<[type]>(null, TrackingMode.None)
memberField.InitExpression = new CodeObjectCreateExpression(
fieldType,
new CodePrimitiveExpression(null),
new CodeFieldReferenceExpression(
new CodeTypeReferenceExpression(typeof(System.Data.Services.Client.TrackingMode)),
"None"));
}
else
{
memberField.InitExpression = new CodeObjectCreateExpression(fieldType);
}
}
typeDecl.Members.Add(memberField);
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:31,代码来源:NavigationPropertyEmitter.cs
示例6: SetBaseType
private void SetBaseType(string modelTypeName)
{
var baseClass = StringExtensions.SplitOnFirst((string) Host.DefaultBaseClass, (char) '<')[0];
var baseType = new CodeTypeReference(baseClass + "<" + modelTypeName + ">");
GeneratedClass.BaseTypes.Clear();
GeneratedClass.BaseTypes.Add(baseType);
}
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:7,代码来源:CSharpRazorCodeGenerator.cs
示例7: ConvertTypeReferenceToString
private static string ConvertTypeReferenceToString(CodeTypeReference reference)
{
StringBuilder builder;
if (reference.ArrayElementType != null)
{
builder = new StringBuilder(ConvertTypeReferenceToString(reference.ArrayElementType));
if (reference.ArrayRank > 0)
{
builder.Append("[");
builder.Append(',', reference.ArrayRank - 1);
builder.Append("]");
}
}
else
{
builder = new StringBuilder(reference.BaseType);
if ((reference.TypeArguments != null) && (reference.TypeArguments.Count > 0))
{
string str = "[";
foreach (CodeTypeReference reference2 in reference.TypeArguments)
{
builder.Append(str);
builder.Append(ConvertTypeReferenceToString(reference2));
str = ", ";
}
builder.Append("]");
}
}
return builder.ToString();
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:CodeTypeReferenceSerializer.cs
示例8: CodeVariableDeclarationStatement
public CodeVariableDeclarationStatement(Type type, String name,
CodeExpression initExpression)
{
this.type = new CodeTypeReference(type);
this.name = name;
this.initExpression = initExpression;
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:CodeVariableDeclarationStatement.cs
示例9: BindingElementExtensionSectionGenerator
internal BindingElementExtensionSectionGenerator(Type bindingElementType, Assembly userAssembly, CodeDomProvider provider)
{
this.bindingElementType = bindingElementType;
this.userAssembly = userAssembly;
this.provider = provider;
string typePrefix = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement));
this.generatedClassName = typePrefix + Constants.ElementSuffix;
this.constantsClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.ConfigurationStrings;
this.defaultValuesClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.Defaults;
this.customBEVarInstance = Helpers.TurnFirstCharLower(bindingElementType.Name);
customBEArgRef = new CodeArgumentReferenceExpression(customBEVarInstance);
this.customBETypeRef = new CodeTypeReference(bindingElementType.Name);
this.customBETypeOfRef = new CodeTypeOfExpression(customBETypeRef);
this.customBENewVarAssignRef = new CodeVariableDeclarationStatement(
customBETypeRef,
customBEVarInstance,
new CodeObjectCreateExpression(customBETypeRef));
this.bindingElementMethodParamRef = new CodeParameterDeclarationExpression(
CodeDomHelperObjects.bindingElementTypeRef,
Constants.bindingElementParamName);
}
开发者ID:ssickles,项目名称:archive,代码行数:25,代码来源:BindingElementExtensionSectionGenerator.cs
示例10: CodeAttributeDeclaration
public CodeAttributeDeclaration (CodeTypeReference attributeType)
{
attribute = attributeType;
if (attributeType != null) {
name = attributeType.BaseType;
}
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:CodeAttributeDeclaration.cs
示例11: Constructor1
public void Constructor1 ()
{
CodeTypeReference type1 = new CodeTypeReference ("mono1");
CodeExpression expression1 = new CodeExpression ();
CodeCastExpression cce = new CodeCastExpression (type1, expression1);
Assert.IsNotNull (cce.Expression, "#1");
Assert.AreSame (expression1, cce.Expression, "#2");
Assert.IsNotNull (cce.TargetType, "#3");
Assert.AreSame (type1, cce.TargetType, "#4");
cce.Expression = null;
Assert.IsNull (cce.Expression, "#5");
CodeExpression expression2 = new CodeExpression ();
cce.Expression = expression2;
Assert.IsNotNull (cce.Expression, "#6");
Assert.AreSame (expression2, cce.Expression, "#7");
cce.TargetType = null;
Assert.IsNotNull (cce.TargetType, "#8");
Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#9");
CodeTypeReference type2 = new CodeTypeReference ("mono2");
cce.TargetType = type2;
Assert.IsNotNull (cce.TargetType, "#10");
Assert.AreSame (type2, cce.TargetType, "#11");
cce = new CodeCastExpression ((CodeTypeReference) null, (CodeExpression) null);
Assert.IsNull (cce.Expression, "#12");
Assert.IsNotNull (cce.TargetType, "#13");
Assert.AreEqual (typeof (void).FullName, cce.TargetType.BaseType, "#14");
}
开发者ID:nlhepler,项目名称:mono,代码行数:33,代码来源:CodeCastExpressionTest.cs
示例12: CodeTypeReference
/// <include file='doc\CodeTypeReference.uex' path='docs/doc[@for="CodeTypeReference.CodeTypeReference1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CodeTypeReference(string typeName) {
if (typeName == null || typeName.Length == 0) {
typeName = typeof(void).FullName;
}
// See if this ends with standard array tail. If is is not an exact match, we pass it through verbatim.
int lastArrayOpen = typeName.LastIndexOf('[');
int lastArrayClose = typeName.LastIndexOf(']');
bool isArray = lastArrayOpen >= 0 && lastArrayClose == (typeName.Length - 1) && lastArrayOpen < lastArrayClose;
if (isArray) {
for (int index = lastArrayOpen + 1; index < lastArrayClose; index++) {
if (typeName[index] != ',') {
isArray = false;
}
}
}
if (isArray) {
this.baseType = null;
this.arrayRank = lastArrayClose - lastArrayOpen;
this.arrayElementType = new CodeTypeReference(typeName.Substring(0, lastArrayOpen));
}
else {
this.baseType = typeName;
this.arrayRank = 0;
this.arrayElementType = null;
}
}
开发者ID:ArildF,项目名称:masters,代码行数:32,代码来源:codetypereference.cs
示例13: Visit
public void Visit(BufferTable table)
{
var descriptor = new TableDescriptor(typeof(BufferTable<>));
var bufferTable = new CodeTypeDeclaration(table.Variable) { TypeAttributes = TypeAttributes.NestedPrivate };
bufferTable.BaseTypes.Add(new CodeTypeReference("IRow"));
var bufferCodeDomType = new CodeTypeReference("CodeTable", new CodeTypeReference(table.Variable));
Scope.Current.Type.Type.Members.Add(
new CodeMemberField(bufferCodeDomType, table.Variable) { Attributes = MemberAttributes.Public | MemberAttributes.Final });
Scope.Current.Type.Constructor.Statements.Add(new CodeAssignStatement(
new CodeSnippetExpression(table.Variable),
new CodeObjectCreateExpression(
new CodeTypeReference("BufferTable", new CodeTypeReference(table.Variable)))));
foreach (var arg in table.Args)
{
var domArg = VisitChild(arg);
bufferTable.Members.AddRange(domArg.ParentMemberDefinitions);
descriptor.Variables.Add(new VariableTypePair { Variable = arg.Variable, Primitive = TablePrimitive.FromString(arg.Type) });
}
_mainType.Type.Members.Add(bufferTable);
if (Scope.Current.IsCurrentScopeRegistered(table.Variable))
Errors.Add(new VariableAlreadyExists(new Semantic.LineInfo(table.Line.Line, table.Line.CharacterPosition), table.Variable));
Scope.Current.RegisterTable(table.Variable, descriptor, bufferCodeDomType);
}
开发者ID:bitsummation,项目名称:pickaxe,代码行数:29,代码来源:Visitor.BufferTable.cs
示例14: SimpleCSharpRazorCodeGenerator
public SimpleCSharpRazorCodeGenerator(string className, string rootNamespaceName, string sourceFileName, RazorEngineHost host)
: base(className, rootNamespaceName, sourceFileName, host)
{
var baseType = new CodeTypeReference(SimpleRazorConfiguration.BaseClass);
Context.GeneratedClass.BaseTypes.Clear();
Context.GeneratedClass.BaseTypes.Add(baseType);
}
开发者ID:muratbeyaztas,项目名称:Simple.Web,代码行数:7,代码来源:SimpleCSharpRazorCodeGenerator.cs
示例15: BeginClass
protected override CodeTypeDeclaration BeginClass ()
{
CodeTypeDeclaration codeClass = base.BeginClass ();
CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.HttpPostClientProtocol");
codeClass.BaseTypes.Add (ctr);
return codeClass;
}
开发者ID:nobled,项目名称:mono,代码行数:7,代码来源:HttpPostProtocolImporter.cs
示例16: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeTypeReference ctr = new CodeTypeReference ();
CodeDefaultValueExpression cdve = new CodeDefaultValueExpression (ctr);
Assert.AreSame (ctr, cdve.Type, "Type");
cdve.Type = new CodeTypeReference ();
}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeDefaultValueExpressionCas.cs
示例17: GetTypeOutput
public string GetTypeOutput(CodeTypeReference type)
{
var name = new StringBuilder(type.BaseType.Length + type.ArrayRank * 2);
string basename = type.BaseType;
int z = basename.IndexOf('`');
if (z != -1)
basename = basename.Substring(0, z);
name.Append(basename);
if (type.TypeArguments.Count > 0)
{
name.Append('<');
for (int i = 0; i < type.TypeArguments.Count; i++)
{
name.Append(GetTypeOutput(type.TypeArguments[i]));
if (i > 0)
name.Append(", ");
}
name.Append('>');
}
for (int i = 0; i < type.ArrayRank; i++)
name.Append("[]");
return name.ToString();
}
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:29,代码来源:Type.cs
示例18: ResourceCallAddBodyDeclaration
protected void ResourceCallAddBodyDeclaration(IMethod method,
CodeMemberMethod member,
CodeTypeReference bodyType,
bool addBodyIfUnused)
{
switch (method.HttpMethod)
{
case Request.GET:
case Request.DELETE:
if (!addBodyIfUnused)
{
break;
}
// string body = null;
var bodyVarDeclaration = new CodeVariableDeclarationStatement(bodyType, "body");
bodyVarDeclaration.InitExpression = new CodePrimitiveExpression(null);
member.Statements.Add(bodyVarDeclaration);
break;
case Request.PUT:
case Request.POST:
case Request.PATCH:
// add body Parameter.
member.Parameters.Add(new CodeParameterDeclarationExpression(bodyType, "body"));
break;
default:
throw new NotSupportedException("Unsupported HttpMethod [" + method.HttpMethod + "]");
}
}
开发者ID:jithuin,项目名称:infogeezer,代码行数:30,代码来源:ResourceBaseGenerator.cs
示例19: Visit
public override void Visit(ViewTreeNode node)
{
if (typeStack.Count == 0) return;
var constructionArguments = new CodeExpression[]
{
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
new CodeTypeOfExpression(node.Controller.FullName),
new CodePrimitiveExpression(node.Controller.Area),
new CodePrimitiveExpression(naming.ToControllerName(node.Controller.Name)),
new CodePrimitiveExpression(node.Name)
};
CodeExpression returnExpression =
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodePropertyReferenceExpression(
new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), naming.ToMemberVariableName(serviceIdentifier)),
"ControllerReferenceFactory"),
"CreateViewReference"),
constructionArguments);
var propertyType = new CodeTypeReference(typeof (IControllerViewReference));
typeStack.Peek().Members.Add(source.CreateReadOnlyProperty(node.Name, propertyType, returnExpression));
base.Visit(node);
}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:27,代码来源:ViewMapGenerator.cs
示例20: Visit
public void Visit(DownloadImageExpression expression)
{
var type = new CodeTypeReference("RuntimeTable", new CodeTypeReference("DownloadImage"));
DownloadImpl(expression.Statement, "DownloadImage", type, expression.Line.Line);
_codeStack.Peek().Scope = new ScopeData<TableDescriptor> { Type = DownloadImage.Columns, CodeDomReference = type };
}
开发者ID:bitsummation,项目名称:pickaxe,代码行数:7,代码来源:Visitor.DownloadImageExpression.cs
注:本文中的System.CodeDom.CodeTypeReference类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论