本文整理汇总了C#中ITypeDefinition类的典型用法代码示例。如果您正苦于以下问题:C# ITypeDefinition类的具体用法?C# ITypeDefinition怎么用?C# ITypeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITypeDefinition类属于命名空间,在下文中一共展示了ITypeDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Creates the <see cref="Table"/> from the descriptor.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="type">The <see cref="ITypeDefinition"/>.</param>
/// <returns>Returns the created <see cref="Table"/>.</returns>
/// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception>
public Table Create(IMansionContext context, ITypeDefinition type)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
if (type == null)
throw new ArgumentNullException("type");
// invoke template method
var table = DoCreate(context, type);
// create the columns for this table
foreach (var property in type.Properties)
{
ColumnDescriptor columnDescriptor;
if (!property.TryGetDescriptor(out columnDescriptor))
continue;
// add the column to the table
table.Add(columnDescriptor.Create(context, table, property));
}
// return the created table
return table;
}
示例2: CreateCodeTypeForTypeDefinition
CodeType CreateCodeTypeForTypeDefinition(ITypeDefinition typeDefinition)
{
if (typeDefinition.Kind == TypeKind.Interface) {
return new CodeInterface(context, typeDefinition);
}
return new CodeClass2(context, typeDefinition);
}
示例3: GenerateCode
protected override string GenerateCode(ITypeDefinition currentClass)
{
// string[] fields = listBox.SelectedItems.OfType<PropertyOrFieldWrapper>().Select(f2 => f2.MemberName).ToArray();
string[] fields = parameterList.Where(f => f.IsIncluded).Select(f2 => f2.MemberName).ToArray();
PrimitiveExpression formatString = new PrimitiveExpression(GenerateFormatString(currentClass, editor.Language.CodeGenerator, fields));
List<Expression> param = new List<Expression>() { formatString };
ReturnStatement ret = new ReturnStatement(new InvocationExpression(
new MemberReferenceExpression(new TypeReferenceExpression(ConvertType(KnownTypeCode.String)), "Format"),
param.Concat(fields.Select(f => new IdentifierExpression(f))).ToList()
));
if (baseCallNode != null) {
MethodDeclaration insertedOverrideMethod = refactoringContext.GetNode().PrevSibling as MethodDeclaration;
if (insertedOverrideMethod == null) {
// We are not inside of a method declaration
return null;
}
using (Script script = refactoringContext.StartScript()) {
NewLineNode nextNewLineNode = insertedOverrideMethod.NextSibling as NewLineNode;
// Find base method call and replace it by return statement
script.AddTo(insertedOverrideMethod.Body, ret);
AppendNewLine(script, insertedOverrideMethod, nextNewLineNode);
}
}
return null;
}
示例4: GetJsClass
private JsClass GetJsClass(ITypeDefinition typeDefinition) {
JsClass result;
if (!_types.TryGetValue(typeDefinition, out result)) {
var semantics = _metadataImporter.GetTypeSemantics(typeDefinition);
if (semantics.GenerateCode) {
var errors = Utils.FindTypeUsageErrors(typeDefinition.GetAllBaseTypes(), _metadataImporter);
if (errors.HasErrors) {
var oldRegion = _errorReporter.Region;
try {
_errorReporter.Region = typeDefinition.Region;
foreach (var ut in errors.UsedUnusableTypes)
_errorReporter.Message(Messages._7500, ut.FullName, typeDefinition.FullName);
foreach (var t in errors.MutableValueTypesBoundToTypeArguments)
_errorReporter.Message(Messages._7539, t.FullName);
}
finally {
_errorReporter.Region = oldRegion;
}
}
result = new JsClass(typeDefinition);
}
else {
result = null;
}
_types[typeDefinition] = result;
}
return result;
}
示例5: OverrideEqualsGetHashCodeMethodsDialog
public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor endAnchor,
ITextAnchor insertionPosition, ITypeDefinition selectedClass, IMethod selectedMethod, AstNode baseCallNode)
: base(context, editor, insertionPosition)
{
if (selectedClass == null)
throw new ArgumentNullException("selectedClass");
InitializeComponent();
this.selectedClass = selectedClass;
this.insertionEndAnchor = endAnchor;
this.selectedMethod = selectedMethod;
this.baseCallNode = baseCallNode;
addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"),
"IEquatable<" + selectedClass.Name + ">");
string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals";
addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod));
addIEquatable.IsEnabled = !selectedClass.GetAllBaseTypes().Any(
type => {
if (!type.IsParameterized || (type.TypeParameterCount != 1))
return false;
if (type.FullName != "System.IEquatable")
return false;
return type.TypeArguments.First().FullName == selectedClass.FullName;
}
);
}
示例6: IsForwardable
public bool IsForwardable(ITypeDefinition type)
{
INestedTypeDefinition nestedType = type as INestedTypeDefinition;
if (nestedType != null)
return false;
return true;
}
示例7: AddedBaseType
private bool AddedBaseType(IDifferences differences, ITypeDefinition impl, ITypeDefinition contract)
{
// For interfaces we rely only on the AddedInterface check
if (impl.IsInterface || contract.IsInterface)
return false;
// Base types must be in the same order so we have to compare them in order
List<ITypeReference> implBaseTypes = new List<ITypeReference>(impl.GetAllBaseTypes());
int lastIndex = 0;
foreach (var contractBaseType in contract.GetAllBaseTypes())
{
lastIndex = implBaseTypes.FindIndex(lastIndex, item1BaseType => _typeComparer.Equals(item1BaseType, contractBaseType));
if (lastIndex < 0)
{
differences.AddIncompatibleDifference(this,
"Type '{0}' does not inherit from base type '{1}' in the implementation but it does in the contract.",
contract.FullName(), contractBaseType.FullName());
return true;
}
}
return false;
}
示例8: MixinsWeaverStrategy
public MixinsWeaverStrategy(ITypeDefinition typeDefinition, ITypeMapCollection mixinsMap, IEnumerable<IMethodWeaver> methodWeavers, INCopDependencyAwareRegistry registry)
{
this.registry = registry;
this.mixinsMap = mixinsMap;
this.methodWeavers = methodWeavers;
this.typeDefinition = typeDefinition;
}
示例9: Unspecialize
public static ITypeReference Unspecialize(ITypeDefinition type) {
var sntd = type as ISpecializedNestedTypeDefinition;
if (sntd != null) return sntd.UnspecializedVersion;
var gti = type as IGenericTypeInstance;
if (gti != null) return gti.GenericType;
return type;
}
示例10: FindDerivedSymbols
static void FindDerivedSymbols (ITypeDefinition cls, IMember member)
{
var solution = IdeApp.ProjectOperations.CurrentSelectedSolution;
if (solution == null)
return;
var sourceProject = TypeSystemService.GetProject (cls);
if (sourceProject == null)
return;
var compilations = ReferenceFinder.GetAllReferencingProjects (solution, sourceProject)
.Select (TypeSystemService.GetCompilation).Where (c => c != null).ToList ();
using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) {
var label = member == null
? GettextCatalog.GetString ("Searching for derived classes in solution...")
: GettextCatalog.GetString ("Searching for derived members in solution...");
monitor.BeginTask (label, compilations.Count);
Parallel.ForEach (compilations, comp => {
try {
SearchCompilation (monitor, comp, cls, member);
} catch (Exception ex) {
LoggingService.LogInternalError (ex);
monitor.ReportError ("Unhandled error while searching", ex);
}
monitor.Step (1);
});
monitor.EndTask ();
};
}
示例11: PrintDelegateDefinition
public virtual void PrintDelegateDefinition(ITypeDefinition delegateDefinition) {
PrintTypeDefinitionAttributes(delegateDefinition);
PrintToken(CSharpToken.Indent);
IMethodDefinition invokeMethod = null;
foreach (var invokeMember in delegateDefinition.GetMatchingMembers(m => m.Name.Value == "Invoke")) {
IMethodDefinition idef = invokeMember as IMethodDefinition;
if (idef != null) { invokeMethod = idef; break; }
}
PrintTypeDefinitionVisibility(delegateDefinition);
if (IsMethodUnsafe(invokeMethod))
PrintKeywordUnsafe();
PrintKeywordDelegate();
PrintMethodDefinitionReturnType(invokeMethod);
PrintToken(CSharpToken.Space);
PrintTypeDefinitionName(delegateDefinition);
if (delegateDefinition.GenericParameterCount > 0) {
this.Traverse(delegateDefinition.GenericParameters);
}
if (invokeMethod != null)
Traverse(invokeMethod.Parameters);
PrintToken(CSharpToken.Semicolon);
}
示例12: PrintTypeDefinition
public virtual void PrintTypeDefinition(ITypeDefinition typeDefinition) {
if (typeDefinition.IsDelegate) {
PrintDelegateDefinition(typeDefinition);
return;
}
if (((INamedEntity)typeDefinition).Name.Value.Contains("PrivateImplementationDetails")) return;
PrintTypeDefinitionAttributes(typeDefinition);
PrintToken(CSharpToken.Indent);
PrintTypeDefinitionVisibility(typeDefinition);
PrintTypeDefinitionModifiers(typeDefinition);
PrintTypeDefinitionKeywordType(typeDefinition);
PrintTypeDefinitionName(typeDefinition);
if (typeDefinition.IsGeneric) {
this.Traverse(typeDefinition.GenericParameters);
}
PrintTypeDefinitionBaseTypesAndInterfaces(typeDefinition);
PrintTypeDefinitionLeftCurly(typeDefinition);
// Get the members in metadata order for each type
// Note that it's important to preserve the metadata order here (eg. sequential layout fields,
// methods in COMImport types, etc.).
var members = new List<ITypeDefinitionMember>();
foreach (var m in typeDefinition.Methods) members.Add(m);
foreach (var m in typeDefinition.Events) members.Add(m);
foreach (var m in typeDefinition.Properties) members.Add(m);
foreach (var m in typeDefinition.Fields) members.Add(m);
foreach (var m in typeDefinition.NestedTypes) members.Add(m);
Traverse(members);
PrintTypeDefinitionRightCurly(typeDefinition);
}
示例13: Visit
public TsType Visit(ITypeDefinition ce)
{
var name = SkJs.GetEntityJsName(ce);
var ce2 = new TsType
{
Name = name, Kind=(ce.IsInterface() || ce.IsDelegate()) ? TsTypeKind.Interface : TsTypeKind.Class,
TypeParameters = ce.TypeParameters.Select(Visit).ToList()
};
if (name.Contains("."))
{
var pair = name.SplitAt(name.LastIndexOf("."), true);
ce2.Name = pair[1];
ce2.ModuleName = pair[0];
ce2.IsModuleExport = true;
}
if (ce.IsDelegate())
{
var func = Visit(ce.GetDelegateInvokeMethod());
//func.IsCallSignature = true;
func.Name = null;
ce2.Members.Add(func);
}
else
{
var members = TypeConverter.ClrConverter.GetMembersToExport(ce);
var members2 = members.Select(Visit).Where(t => t != null).ToList();
ce2.Members.AddRange(members2);
if (ce2.Kind == TsTypeKind.Class)
{
ce2.Members.OfType<TsFunction>().Where(t => !t.IsConstructor || !t.Type.IsNullOrVoid()).ForEach(t => t.Body = "return null;");
ce2.Members.OfType<TsFunction>().Where(t => t.IsConstructor).ForEach(t => t.Body = "");
}
}
return ce2;
}
示例14: Diff
public override DifferenceType Diff(IDifferences differences, ITypeDefinition impl, ITypeDefinition contract)
{
if (impl == null || contract == null)
return DifferenceType.Unknown;
return DiffConstraints(differences, impl, impl.GenericParameters, contract.GenericParameters);
}
示例15: Include
public bool Include(ITypeDefinition type)
{
string typeId = type.DocId();
// include so long as it isn't in the exclude list.
return !_docIds.Contains(typeId);
}